#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
#define sort stable_sort
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
	(read(args),...);
}
template<typename TP> inline void write(TP x)
{
	(x<0)?(putchar('-'),x=-x):0;
	(x>9)?(write(x/10),0):0;
	putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
	write<TP>(x);
	puts("");
}
constexpr int mod=999999999;
signed main()
{
	freopen("ex_fire2.in","r",stdin);
	freopen("fire.out","w",stdout);
	int n,q; read(n,q);
	vector<vector<int>> val(n+1,vector<int>(n+1));
	while(q--)
	{
		int opt; read(opt);
		if(opt==1)
		{
			int type,rc,calc,arg; read(type,rc,calc,arg);
			auto getNew=[&](int orig)
			{
/*
				if(calc==1) return orig&arg;
				if(calc==2) return orig|arg;
				if(calc==3) return orig^arg;
				return (orig+arg)%mod;*/
				////////////////////////////
				return (calc==1)?(orig&arg):(
						(calc==2)?(orig|arg):(
							(calc==3)?(orig^arg):(
								((orig+arg)>=mod)?(orig+arg-mod):(orig+arg)
							)
						)
					);
			};
			if(!type)rep(j,1,n)val[rc][j]=getNew(val[rc][j]);
			else rep(i,1,n)val[i][rc]=getNew(val[i][rc]);
		/*	int i=!type?rc:1,j=type?rc:1;
			for(;(type?i:j)<=n;++(type?i:j))
			{
				int diff=getDiff(val[i][j]);
				val[i][j]+=diff;
			}*/
		}
		else
		{
			int xlim,ylim; read(xlim,ylim);
			int brute_ans=0;
			rep(i,1,xlim)rep(j,1,ylim)brute_ans+=val[i][j];
			writeln(brute_ans);
		}
	}
	return 0;
}
